package demo1;

import java.util.HashSet;
import java.util.Iterator;
import java.util.MissingFormatArgumentException;
import java.util.Set;

@SuppressWarnings({"all"})
class Dog{
    private String name;

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
public class test {

    @SuppressWarnings({"all"})
    public static void main(String[] args) {
         Set hashSet = new HashSet();
         hashSet.add("lucy");//添加成功
         hashSet.add("lucy");//无法添加成功
         //hashSet.add(new Dog("tom"));
         //ashSet.add(new Dog("tom"));
         //经典面试题目：
         //hashSet.add(new String("hsp"));
         //hashSet.add(new String("hsp"));
        System.out.println(hashSet);
    }





    public static void main1(String[] args) {
        Set set = new HashSet();
        set.add("hello1");
        set.add("hello1");
        set.add("hello1");
        set.add("hello2");
        set.add("hello3");
        set.add(5);
        System.out.println(set);

        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }

        System.out.println("增强for循环");
        for (Object o : set) {
            System.out.println(o);
        }
        //不可以使用for进行遍历，无get方法

    }
}
